package o;

import android.content.res.ColorStateList;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import o.ah.g;

@RestrictTo({d.ˊ})
public class ce {
    private cu ˊ;
    private cu ˎ;
    private final ImageView ˏ;
    private cu ॱ;

    public ce(ImageView imageView) {
        this.ˏ = imageView;
    }

    public void ˋ(AttributeSet attributeSet, int i) {
        cw ॱ = cw.ॱ(this.ˏ.getContext(), attributeSet, g.ﹳ, i, 0);
        try {
            Drawable drawable = this.ˏ.getDrawable();
            if (drawable == null) {
                int ॱॱ = ॱ.ॱॱ(g.ﾞ, -1);
                if (ॱॱ != -1) {
                    drawable = ar.ˋ(this.ˏ.getContext(), ॱॱ);
                    if (drawable != null) {
                        this.ˏ.setImageDrawable(drawable);
                    }
                }
            }
            if (drawable != null) {
                cl.ˎ(drawable);
            }
            if (ॱ.ᐝ(g.ʹ)) {
                iz.ˎ(this.ˏ, ॱ.ॱ(g.ʹ));
            }
            if (ॱ.ᐝ(g.ʻˊ)) {
                iz.ˎ(this.ˏ, cl.ˏ(ॱ.ॱ(g.ʻˊ, -1), null));
            }
            ॱ.ॱ();
        } catch (Throwable th) {
            ॱ.ॱ();
        }
    }

    public void ˊ(int i) {
        if (i != 0) {
            Drawable ˋ = ar.ˋ(this.ˏ.getContext(), i);
            if (ˋ != null) {
                cl.ˎ(ˋ);
            }
            this.ˏ.setImageDrawable(ˋ);
        } else {
            this.ˏ.setImageDrawable(null);
        }
        ˊ();
    }

    public boolean ˏ() {
        Drawable background = this.ˏ.getBackground();
        if (VERSION.SDK_INT < 21 || !(background instanceof RippleDrawable)) {
            return true;
        }
        return false;
    }

    public void ˋ(ColorStateList colorStateList) {
        if (this.ˊ == null) {
            this.ˊ = new cu();
        }
        this.ˊ.ˋ = colorStateList;
        this.ˊ.ˎ = true;
        ˊ();
    }

    public ColorStateList ˎ() {
        return this.ˊ != null ? this.ˊ.ˋ : null;
    }

    public void ˊ(Mode mode) {
        if (this.ˊ == null) {
            this.ˊ = new cu();
        }
        this.ˊ.ˏ = mode;
        this.ˊ.ˊ = true;
        ˊ();
    }

    public Mode ॱ() {
        return this.ˊ != null ? this.ˊ.ˏ : null;
    }

    public void ˊ() {
        Drawable drawable = this.ˏ.getDrawable();
        if (drawable != null) {
            cl.ˎ(drawable);
        }
        if (drawable == null) {
            return;
        }
        if (!ˋ() || !ॱ(drawable)) {
            if (this.ˊ != null) {
                bx.ˏ(drawable, this.ˊ, this.ˏ.getDrawableState());
            } else if (this.ˎ != null) {
                bx.ˏ(drawable, this.ˎ, this.ˏ.getDrawableState());
            }
        }
    }

    private boolean ˋ() {
        int i = VERSION.SDK_INT;
        if (i > 21) {
            if (this.ˎ != null) {
                return true;
            }
            return false;
        } else if (i != 21) {
            return false;
        } else {
            return true;
        }
    }

    private boolean ॱ(@NonNull Drawable drawable) {
        if (this.ॱ == null) {
            this.ॱ = new cu();
        }
        cu cuVar = this.ॱ;
        cuVar.ॱ();
        ColorStateList ॱ = iz.ॱ(this.ˏ);
        if (ॱ != null) {
            cuVar.ˎ = true;
            cuVar.ˋ = ॱ;
        }
        Mode ˊ = iz.ˊ(this.ˏ);
        if (ˊ != null) {
            cuVar.ˊ = true;
            cuVar.ˏ = ˊ;
        }
        if (!cuVar.ˎ && !cuVar.ˊ) {
            return false;
        }
        bx.ˏ(drawable, cuVar, this.ˏ.getDrawableState());
        return true;
    }
}
